1
|
|
|
var assert = require('chai').assert, |
2
|
|
|
GedcomX = require('../'); |
3
|
|
|
|
4
|
|
|
describe('ResourceReference', function(){ |
5
|
|
|
|
6
|
|
|
it('Create plain', function(){ |
7
|
|
|
var newRR = new GedcomX.ResourceReference(), |
8
|
|
|
rr = GedcomX.ResourceReference(); |
9
|
|
|
assert.instanceOf(newRR, GedcomX.ResourceReference, 'An instance of ResourceReference is not returned when calling the constructor with new.'); |
10
|
|
|
assert.instanceOf(rr, GedcomX.ResourceReference, 'An instance of ResourceReference is not returned when calling the constructor without new.'); |
11
|
|
|
}); |
12
|
|
|
|
13
|
|
|
it('Create with JSON', function(){ |
14
|
|
|
var rr = GedcomX.ResourceReference({ resource: 'http://example.com' }); |
15
|
|
|
assert.equal(rr.getResource(), 'http://example.com', 'Resource not saved properly when created with JSON'); |
16
|
|
|
}); |
17
|
|
|
|
18
|
|
|
it('Change resource', function(){ |
19
|
|
|
var rr = GedcomX.ResourceReference({ resource: 'http://example.com' }); |
20
|
|
|
rr.setResource('http://newuri.com'); |
21
|
|
|
assert.equal(rr.getResource(), 'http://newuri.com', 'Resource not saved properly when changed with setResource()'); |
22
|
|
|
}); |
23
|
|
|
|
24
|
|
|
it('toJSON()', function(){ |
25
|
|
|
var rr = GedcomX.ResourceReference({ resource: 'http://example.com' }); |
26
|
|
|
rr.setResource('http://newuri.com'); |
27
|
|
|
assert.deepEqual(rr.toJSON(), { resource: 'http://newuri.com' }, 'JSON export is incorrect'); |
28
|
|
|
|
29
|
|
|
rr = GedcomX.ResourceReference(); |
30
|
|
|
assert.deepEqual(rr.toJSON(), {}); |
31
|
|
|
}); |
32
|
|
|
|
33
|
|
|
it('constructor does not copy instances', function(){ |
34
|
|
|
var obj1 = GedcomX.ResourceReference(); |
35
|
|
|
var obj2 = GedcomX.ResourceReference(obj1); |
36
|
|
|
assert.strictEqual(obj1, obj2); |
37
|
|
|
}); |
38
|
|
|
|
39
|
|
|
}); |